package cn.star.jots.records.controller;

import cn.star.jots.base.response.JsonResult;
import cn.star.jots.records.pojo.dto.RecordsQuery;
import cn.star.jots.records.pojo.dto.RecordsSaveParam;
import cn.star.jots.records.pojo.dto.RecordsUpdateParam;
import cn.star.jots.records.pojo.entity.Records;
import cn.star.jots.records.pojo.vo.RecordsVO;
import cn.star.jots.records.service.RecordsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/records")
@Api(tags = "观看记录")
@Slf4j
public class RecordsController {

    @Autowired
    RecordsService recordsService;

    @PostMapping("/save")
    @ApiOperation(value = "保存观看记录")
    public JsonResult save(RecordsSaveParam recordsSaveParam) {
        log.info("保存观看记录:recordsSaveParam={}", recordsSaveParam);
        recordsService.save(recordsSaveParam);
        RecordsVO recordsVO = recordsService.save(recordsSaveParam);
        log.info("保存观看记录成功,recordsVO={}", recordsVO);
        return JsonResult.ok(recordsVO);
    }

    @GetMapping("/select")
    @ApiOperation(value = "查询观看记录")
    public JsonResult select(RecordsQuery recordsQuery) {
        log.info("查询记录:recordsQuery={}", recordsQuery);
        List<Records> list = recordsService.select(recordsQuery);
        return JsonResult.ok(list);
    }


    @PutMapping("/update")
    @ApiOperation(value = "更新观看记录")
    public JsonResult update(RecordsUpdateParam recordsUpdateParam) {
        log.info("更新观看记录:recordsUpdateParam={}", recordsUpdateParam);
        recordsService.update(recordsUpdateParam);
        return JsonResult.ok();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除观看记录")
    public JsonResult delete(@PathVariable Long id) {
        log.info("删除观看记录:id={}", id);
        recordsService.delete(id);
        return JsonResult.ok();
    }
}
